package com.gxa.saas.service.impl;

import com.gxa.saas.mapper.CompanyMapper;
import com.gxa.saas.mapper.DepartmentMapper;
import com.gxa.saas.pojo.Company;
import com.gxa.saas.pojo.Department;
import com.gxa.saas.service.CompanyService;
import com.gxa.saas.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author wanghai
 * @date 2022/6/7 19:08
 */
@Service("departmentService")
@Transactional(rollbackFor = {Throwable.class})
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public List<Department> selectByPage(Map map) {
        Integer page = (Integer)map.get("page");
        map.put("page",(page-1)*10);
        List<Department> departments = departmentMapper.selectByPage(map);

        return departments;
    }

    @Override
    public void addDepartment(Department department) {
        departmentMapper.addDepartment(department);
    }

    @Override
    public void deleteDepartment(Integer id) {
        departmentMapper.deleteDepartment(id);
    }

    @Override
    public void updateDepartment(Department department) {
        departmentMapper.updateDepartment(department);
    }

    @Override
    public void updateIsUsed(Department department) {
        departmentMapper.changeIsUsed(department);
    }

    @Override
    public Integer selectAll() {
        return departmentMapper.selectAll();
    }
}
